﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;


using LRSTaxServices.Biz;
using LRSTaxServices.Common;

public partial class AdminLRS_ManageTaxServicesSchedular : System.Web.UI.Page
{
    #region Types

    public enum LayoutType
    {
        Add,
        Edit,
        Search,
        View
    }

    #endregion

    #region Constants

    private const string PROP_DATASRC_TaxServicesSchedular = "__TaxServicesSchedular::TaxServicesSchedular";
    private const string PROP_LAYOUT = "__TaxServicesSchedular::UIL";
    private const string PROP_SELECTED_TaxServicesSchedular_ID = "__TaxServicesSchedular::STaxServicesSchedularID";

    #endregion

    #region Public Properties

    public TaxServicesSchedularCollection DataSourceTaxServicesSchedular
    {
        get { return (SessionMgr.Session[PROP_DATASRC_TaxServicesSchedular] is TaxServicesSchedularCollection ? (TaxServicesSchedularCollection)SessionMgr.Session[PROP_DATASRC_TaxServicesSchedular] : (TaxServicesSchedularCollection)(SessionMgr.Session[PROP_DATASRC_TaxServicesSchedular] = new TaxServicesSchedularCollection())); }
        set { SessionMgr.Session[PROP_DATASRC_TaxServicesSchedular] = value; }
    }

    public int SelectedScheduleID
    {
        get { return (SessionMgr.Session[PROP_SELECTED_TaxServicesSchedular_ID] is int ? (int)SessionMgr.Session[PROP_SELECTED_TaxServicesSchedular_ID] : 0); }
        set { SessionMgr.Session[PROP_SELECTED_TaxServicesSchedular_ID] = value; }
    }


    public LayoutType UILayout
    {
        get { return (SessionMgr.Session[PROP_LAYOUT] is LayoutType ? (LayoutType)SessionMgr.Session[PROP_LAYOUT] : LayoutType.Search); }
        set { SessionMgr.Session[PROP_LAYOUT] = value; }
    }


    #endregion

    #region Event Handlers

    #region Page Load

    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Cache.SetCacheability(HttpCacheability.NoCache);

        if (!Page.IsPostBack)
        {
            DataSourceTaxServicesSchedular = TaxServicesSchedular.GetAllTaxServicesSchedulars();
            TaxServicesSchedularList1.DataBind(DataSourceTaxServicesSchedular);
            //divexistname.Visible = false;
        }
    }

    #endregion

    #region Control: TaxServicesSchedularList

    protected void ucTaxServicesSchedularList_EditRequested(object sender, Controls_TaxServicesSchedularList.EditRequestedEventArgs evt)
    {
        SelectedScheduleID = evt.TSS.ScheduleID;
        TaxServicesSchedularViewEdit1.DataBind(evt.TSS);
        SetLayout(LayoutType.Edit);
        //divexistname.Visible = false;
    }


    protected void ucTaxServicesSchedularList_AddNewRequested(object sender, EventArgs evt)
    {
        TaxServicesSchedularViewEdit1.CancelEdit();
        TaxServicesSchedular newTaxServicesSchedular = TaxServicesSchedular.CreateNew(DataSourceTaxServicesSchedular);
        SelectedScheduleID = newTaxServicesSchedular.ScheduleID;
        TaxServicesSchedularViewEdit1.DataBind(DataSourceTaxServicesSchedular.FindBySchedularID(SelectedScheduleID));
        SetLayout(LayoutType.Edit);
        //divexistname.Visible = false;
    }


    protected void ucTaxServicesSchedularList_DataSourceRequested(object sender, EventArgs evt)
    {
        DataSourceTaxServicesSchedular = TaxServicesSchedular.GetAllTaxServicesSchedulars();
        TaxServicesSchedularList1.DataSource = DataSourceTaxServicesSchedular;
    }

    #endregion

    #region Control: TaxServicesSchedularViewEdit

    protected void ucTaxServicesSchedularViewEdit_DataSourceUserRequested(object sender, EventArgs evt)
    {
        TaxServicesSchedularViewEdit1.DataSourceTaxServicesSchedular = DataSourceTaxServicesSchedular.FindBySchedularID(SelectedScheduleID);
    }

    #endregion

    #region Save / Cancel Buttons

    protected void btnCancel_Click(object sender, ImageClickEventArgs e)
    {
        TaxServicesSchedularViewEdit1.CancelEdit();
        // If we were adding a new jobcategory...then remove the incomplete/not added new jobcategory object from the collection.
        if (DataSourceTaxServicesSchedular.FindBySchedularID(SelectedScheduleID).ObjState == BOBase.ObjectState.Added)
        {
            try
            {
                DataSourceTaxServicesSchedular.Remove(DataSourceTaxServicesSchedular.FindBySchedularID(SelectedScheduleID));
                SelectedScheduleID = (DataSourceTaxServicesSchedular[0] != null ? DataSourceTaxServicesSchedular[0].ScheduleID : 0);
            }
            catch
            {
            }
        }
        TaxServicesSchedularList1.DataBind(DataSourceTaxServicesSchedular);
        SetLayout(LayoutType.View);
    }
    protected void btnsave_Click(object sender, ImageClickEventArgs e)
    {
        if (TaxServicesSchedularViewEdit1.EndEdit())
        {
            TaxServicesSchedular obj = DataSourceTaxServicesSchedular.FindBySchedularID(SelectedScheduleID);
            TaxServicesSchedular.Update(obj);
            //Set the feedback text here.....
            DataSourceTaxServicesSchedular = TaxServicesSchedular.GetAllTaxServicesSchedulars();
            TaxServicesSchedularList1.DataBind(DataSourceTaxServicesSchedular);
            SetLayout(LayoutType.View);
            Response.AppendHeader("Refresh", "0");
            //divexistname.Visible = false;
        }
        //else
        //{
        //    divexistname.Visible = true;
        //}
    }


    #endregion

    #endregion

    #region Private

    #region SetLayout

    /// <summary>
    /// Configures the UI for the specified 'uiLayoutType'.
    /// </summary>
    protected void SetLayout(LayoutType uiLayoutType)
    {
        switch (uiLayoutType)
        {
            case LayoutType.Add:
            case LayoutType.Edit:

                pnlTaxServicesSchedularList.Visible = false;
                pnlTaxServicesSchedularViewEdit.Visible = true;
                pnlButtons.Visible = true;
                break;

            case LayoutType.View:
            case LayoutType.Search:

                pnlTaxServicesSchedularList.Visible = true;
                pnlTaxServicesSchedularViewEdit.Visible = false;
                pnlButtons.Visible = false;
                break;

            default:
                throw new NotImplementedException("The specified LayoutType is not supported in this release.");
        }

        //SetInitialFocus(uiLayoutType);
    }

    #endregion

    #endregion
}
